<template>
	<view class="bgView">
		<view class="gridTitle">{{roleName}}</view>
		<!-- 轮播图 -->
		<view class="swiper-view">
			<swiper class="swiper" indicator-dots="true" autoplay="true" circular="true" indicator-active-color="#ffffff">
				<swiper-item v-for="swiper in swiperList" :key="swiper.sid" @tap="toSwiper(swiper)">
					<image class="swiperImg" mode="aspectFill" :src="swiper.img"></image>
				</swiper-item>
			</swiper>
			<!-- <view class="keep-out"></view> -->
		</view>
		<uni-notice-bar scrollable="true" showIcon="true" @getmore="getMoreNotice" moreText="查看更多" single="true" :text="showingNotice.title"
		 @click='clickNotice'>
		</uni-notice-bar>
		<view class="menu" v-for="(item,index) in menuList" :key="index">
			<view class="gridTitle">{{item.name}}</view>
			<uni-grid :pdata='item.list' column-num='4' :badge="waitEventBadge" @click='clickGridItem'  :showBorder='false'></uni-grid>
			<view class="menu-line" v-if="menuList.length != index+1"></view>
			
		</view>
		<view style="height: 120upx;"></view>
	</view>
</template>

<script>
	import uniGrid from "@/components/uni-grid/uni-grid.vue"
	import uniNoticeBar from "@/components/uni-notice-bar/uni-notice-bar.vue"

	export default {
		components: {
			uniGrid,
			uniNoticeBar,
		},
		data() {
			return {
				//轮播
				swiperList: [{
						sid: 0,
						src: '自定义src0',
						img: '../../static/img/swiper-img/n1.jpg'
					},
					{
						sid: 1,
						src: '自定义src1',
						img: '../../static/img/swiper-img/n2.jpg'
					}
				],
				roleName: "",
				noticeList: [],
				showingNotice: {
					title: '暂无系统通知，请稍后留意'
				},
				showingIndex: 0,
				menuList: [],
				waitEventBadge: '2',
			};
		},
		onShow() {
			//获取角标
			// if(getApp().globalData.userInfo){
			this.$http.get('ac/xagrid/appNoticeService/getNoticeCount').then((res) => {
				if (res.errcode === '0') {
					this.waitEventBadge = res.data.event+'';
				}
			})
			// }

		},
		onLoad() {
			console.log("这是用户信息 " + getApp().globalData.userInfo);
			this.$http.get('ac/xagrid/appUserService/getUserInfo').then((res) => {
				if (res.errcode === '0') {
					console.log('首页获取用户信息：' + JSON.stringify(res));
					this.roleName = res.data.gridName +'/'+ res.data.roleName +'/'+ res.data.name;
					getApp().globalData.userInfo = res.data;
					if (undefined === res.data.photo) {
						getApp().globalData.photo = '';
					} else {
						getApp().globalData.photo = res.data.photo;
					}
					if (undefined === res.data.mobile) {
						getApp().globalData.mobile = '';
					} else {
						getApp().globalData.mobile = res.data.mobile;
					}
					this.getMainData();
				} else {

				}
			})


		},
		onReady() {

		},
		methods: {
			getMainData() {

				//获取首页功能
				var self = this;
				this.$http.get('ac/xagrid/PcGridMenuService/menuList').then((res) => {
					if (res.errcode == 0) {
						self.menuList = res.data[0].list;
					}

				})
				//公告列表
				this.$http.get('ac/xagrid/appNoticeService/getHomeNoticeList').then((res) => {
					if (res.errcode == 0) {
						console.log('公告' + JSON.stringify(res));
						if (res.data.length > 0) {
							this.noticeList = res.data;
							this.showingNotice = this.noticeList[0];
							if (this.noticeList.length > 0) {
								setInterval(this.changeNotice, 5000);
							}
						}
					}


				});
				var clientInfo = plus.push.getClientInfo();
				console.log('clientInfo -------' + JSON.stringify(clientInfo));
				this.$http.post('ac/xagrid/appUserService/updateUser', {
					pushClientId: clientInfo.clientid
				}).then((res) => {
					console.log('上传用户id' + JSON.stringify(res));
				})

			},
			//轮播图跳转
			toSwiper(e) {
// 				uni.showToast({
// 					title: e.src
// 				});
			},
			clickGridItem: function(e) {
				var item = e.item;
				uni.navigateTo({
					url: item.href
				})
			},
			//轮播显示消息
			changeNotice() {
				this.showingIndex++;
				if (this.showingIndex >= this.noticeList.length) {
					this.showingNotice = this.noticeList[0];
					this.showingIndex = 0;
				} else {
					this.showingNotice = this.noticeList[this.showingIndex];
				}
			},
			getMoreNotice() {
				uni.switchTab({
					url: '../news/news'
				})
			},
			clickNotice() {
				if (!this.showingNotice.id) {
					return;
				}
				uni.navigateTo({
					url: '/pages/news/list2detail-detail/list2detail-detail?id=' + this.showingNotice.id,
				});
			}
		}
	}
</script>

<style lang="scss">
	.bgView {
		width: 100%;
		height: 100%;
	}

	.gridTitle {
		color: #56b98c;
		margin: 20upx;
		font-weight: bold;
		font-size: 32upx;
	}

	.menu {
		height: 100%;
		width: 100%;
		/* height: 100upx; */
		/* background-color: #8F8F94; */
		display: flex;
		flex-direction: column;
	}

	/* .swiper-view { */
	.swiper {
		width: 100%;
		height: 280upx;
		/* image {
			width: 100%;
			height: 280upx;
		} */
	}

	.swiperImg {
		width: 100%;
		height: 280upx;
	}
	.menu .uni-grid-item-text{
		font-size: 26upx;
	}
	.menu .menu-line{
		border-bottom: 2upx solid #e0d8d8;
		width: 96%;
		margin-left: 2%;
	}
	.menu .menu-line-last{
		padding-bottom: 60upx;
	}
	/* .keep-out {
		width: 100%;
		height: 30upx;
		border-radius: 100% 100% 0 0;
		background-color: #ff570a;
		margin-top: -15upx;
		position: absolute;
	} */
	/* } */
</style>
